package com.sdi.columbus;

import org.achartengine.ChartFactory;
import org.achartengine.GraphicalView;
import org.achartengine.model.CategorySeries;
import org.achartengine.renderer.DefaultRenderer;
import org.achartengine.renderer.SimpleSeriesRenderer;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.widget.FrameLayout;

public class Chart {
	private GraphicalView ChartView1;
	private GraphicalView mChartView2;
	int count=0;
	DisplayReport gets=new DisplayReport();
	double g=gets.getSpeed1();
	int val=gets.getValue();
	double r=100-g;
	int[] Mycolors = new int[] {Color.parseColor("#83a046"),Color.parseColor("#d94a38")};
	public Intent execute(Context context,FrameLayout frames) {
	
	
	CategorySeries categorySeries = new CategorySeries("Speed");
	if(g>0)
	{
	categorySeries.add("Safe Driving",g);
	count=count+1;
	}
	if(r>0) 
	{
	categorySeries.add("Rash Driving",r);
	count=count+1;
	}
	int[] colors = new int[count];
	for(int i=0;i<count;i++)
	{
	colors[i]=Mycolors[i];
	}
	DefaultRenderer renderer = buildCategoryRenderer(colors);
	renderer.setShowLabels(false);
	renderer.setShowLegend(true);
	if(val<280)
	{
	renderer.setLegendTextSize(15);
	}
	else
	{
	renderer.setLegendTextSize(22);
	}
	renderer.setScale(1.25f);
	//renderer.setChartTitle("Speed Details");
	//renderer.setLabelsTextSize(12); 
	ChartView1=ChartFactory.getPieChartView(context, categorySeries,renderer);
	frames.addView(ChartView1);
	return ChartFactory.getPieChartIntent(context, categorySeries, renderer,null);
	}
	protected DefaultRenderer buildCategoryRenderer(int[] colors)
	{
	DefaultRenderer renderer = new DefaultRenderer();
	for (int color : colors) {
	SimpleSeriesRenderer r = new SimpleSeriesRenderer();

	r.setColor(color);
	renderer.addSeriesRenderer(r);
	}
	return renderer;
	}

}
